﻿using AutoMapper;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MultipleDB.IServices.Basara;
using PineLake.Drmwe.Lib.EnumText;
using PineLake.Drmwe.Lib.ResultMsg;
using PineLake.Entitys.Dto;

namespace RepositoryMultipleDataBases.Controllers.Basara
{
    /// <summary>
    /// 
    /// </summary>
    //[Authorize]    //Token
    [ApiController]
    [ApiVersion("1.0")]//不带版本号的默认1.0
    [Route("api/[controller]")]
    public class AccountInfoController : ControllerBase
    {
        private readonly IAccountInfo_Services _AccountInfoServices;
        private readonly IMapper _Mapper;
        private ApiResultMsg? ApiResultMsg;
        public AccountInfoController(IMapper Mapper, IAccountInfo_Services IAccountInfoServices)
        {
            _Mapper = Mapper;
            _AccountInfoServices = IAccountInfoServices;
        }

        /// <summary>
        /// 添加  一条数据
        /// </summary>
        /// <param name="AddModel">添加 Dto</param>
        /// <returns></returns>
        [HttpPost("Add/")]
        public async Task<IActionResult> AddAccountInfoAsync(Add_AccountInfo_Dto AddModel)
        {
            ApiResultMsg = new ApiResultMsg
            {
                StatusCode = (int)ApiStatusCodeEnum.Success,
                Info = ApiStatusCodeEnum.Success.GetEnumText(),
                Data = await _AccountInfoServices.AddAsync(AddModel)
            };
            return Ok(ApiResultMsg);
        }

        /// <summary>
        /// 删除  一条数据,通过主键Id
        /// </summary>
        /// <param name="DeleteModel">删除一条数据  Dto</param>
        /// <returns></returns>
        [HttpDelete("Delete/")]
        public async Task<IActionResult> DeleteAccountInfoAsync(Delete_AccountInfo_ByIdDto DeleteModel)
        {
            ApiResultMsg = new ApiResultMsg
            {
                StatusCode = (int)ApiStatusCodeEnum.Success,
                Info = ApiStatusCodeEnum.Success.GetEnumText(),
                Data = await _AccountInfoServices.DeleteAsync(DeleteModel)
            };
            return Ok(ApiResultMsg);
        }

        /// <summary>
        /// 获取一条数据,通过主键Id
        /// </summary>
        /// <param name="GetModel"> Dto</param>
        /// <returns></returns>
        [HttpGet("GetById/")]
        public async Task<IActionResult> GetAccountInfoAsync([FromQuery] Get_AccountInfo_ByIdDto GetModel)
        {
            ApiResultMsg = new ApiResultMsg
            {
                StatusCode = (int)ApiStatusCodeEnum.Success,
                Info = ApiStatusCodeEnum.Success.GetEnumText(),
                Data = await _AccountInfoServices.GetAsync(GetModel)
            };
            return Ok(ApiResultMsg);
        }
        [HttpGet("GetList/")]
        public async Task<IActionResult> GetAccountListInfoAsync()
        {
            ApiResultMsg = new ApiResultMsg
            {
                StatusCode = (int)ApiStatusCodeEnum.Success,
                Info = ApiStatusCodeEnum.Success.GetEnumText(),
                Data = await _AccountInfoServices.QueryAsync()
            };
            return Ok(ApiResultMsg);
        }

        /// <summary>
        /// 修改 一条数据.通过主键Id
        /// </summary>
        /// <param name="ModifyModel">修改  Dto</param>
        /// <returns></returns>
        [HttpPut("Modify/")]
        public async Task<IActionResult> ModifyAccountInfoAsync(Modify_AccountInfo_Dto ModifyModel)
        {
            ApiResultMsg = new ApiResultMsg
            {
                StatusCode = (int)ApiStatusCodeEnum.Success,
                Info = ApiStatusCodeEnum.Success.GetEnumText(),
                Data = await _AccountInfoServices.ModifyAsync(ModifyModel)
            };
            return Ok(ApiResultMsg);
        }
    }
}
